<?php

namespace App\Http\Controllers\CmsApi;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use App\Lib\Response;
use App\Http\Controllers\BaseController;
use App\Http\Model\Hint;
use App\Http\Services\EquipServices;


class InnerEquipController extends BaseController
{
    protected $equipServices;

    public function __construct()
    {
        $this->equipServices = new EquipServices();

    }

    /**
     * 给指定用户发装备
     */
    public function sendEquipToUser(Request $request)
    {
        $equipList = $request->post('equip_list');
        $equipList = json_decode($equipList, true);
        if(empty($equipList)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $data = $this->equipServices->sendEquipToUser($equipList);
        Response::returnResult($data['code'], $data['data'], $data['msg']);
    }

    /**
     * 获取装备类型
     */
    public function getEquipType(Request $request)
    {
        $data = $this->equipServices->getEquipType();

        Response::returnResult(Hint::SUCCESS, $data);
    }

    /**
     * 编辑装备
     */
    public function editEquip(Request $request)
    {
        $equipId = $request->input("equip_id");
        $param['equip_name'] = $request->input("equip_name");
        $param['g_name'] = $request->input("g_name");
        $param['equip_level'] = $request->input("equip_level");
        $param['can_sale'] = $request->input("can_sale");
        $param['can_recoup'] = $request->input("can_recoup");
        $param['can_bag_show'] = $request->input("can_bag_show");
        $param['small_image'] = getUrlPath($request->input("small_image"));
        $param['image'] = getUrlPath($request->input("image"));
        $param['jd_price'] = $request->input("jd_price");
        $param['jd_sale_price_jd'] = $request->input("jd_sale_price_jd");
        $param['jd_return_max'] = $request->input("jd_return_max");
        if(empty($equipId)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $data = $this->equipServices->editEquip($equipId, $param);
        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $data['data']);
    }

    /**
     * 装备货架新增
     */
    public function addEquipShelve(Request $request)
    {
        $param['equip_id'] = $request->input("equip_id");
        $param['shelve_name'] = $request->input("shelve_name");
        $param['shelve_image'] = getUrlPath($request->input("shelve_image"));
        $param['price_type'] = $request->input("price_type");
        $param['price'] = $request->input("price");
        if(empty($param['equip_id']) || empty($param['shelve_name']) || empty($param['shelve_image']) || empty($param['price'])) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $data = $this->equipServices->addEquipShelve($param);
        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $data['data']);
    }

    /**
     * 装备货架编辑
     */
    public function editEquipShelve(Request $request)
    {
        $shelveId = $request->input("shelve_id");
        $param['shelve_name'] = $request->input("shelve_name");
        $param['shelve_image'] = getUrlPath($request->input("shelve_image"));
        $param['price_type'] = $request->input("price_type");
        $param['price'] = $request->input("price");
        if(empty($shelveId)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $data = $this->equipServices->editEquipShelve($shelveId, $param);
        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $data['data']);
    }

    /**
     * 装备货架删除
     */
    public function delEquipShelve(Request $request)
    {
        $shelveId = $request->input("shelve_id");
        if(empty($shelveId)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $data = $this->equipServices->delEquipShelve($shelveId);
        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $data['data']);
    }

    /**
     * 编辑装备类型
     */
    public function editEquipType(Request $request)
    {
        $id = $request->input("id");
        $param['sort'] = (int) $request->input("sort");
        if(empty($id)) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $data = $this->equipServices->editEquipType($id, $param);
        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $data['data']);
    }











}